package com.example.newsapp.viewmodel;

import android.app.Application;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.newsapp.model.entity.User;
import com.example.newsapp.model.repository.UserRepository;

public class ProfileViewModel extends AndroidViewModel {
    private UserRepository repository;
    private MutableLiveData<Boolean> logoutResult = new MutableLiveData<>();

    public ProfileViewModel(Application application) {
        super(application);
        repository = new UserRepository(application);
    }

    public void loadUserInfo() {
        repository.loadCurrentUser();
    }

    public void changePassword(String oldPassword, String newPassword) {
        repository.changePassword(oldPassword, newPassword);
    }

    public void logout() {
        repository.logout();
        logoutResult.setValue(true);
    }

    public LiveData<User> getCurrentUser() {
        return repository.getCurrentUser();
    }

    public LiveData<String> getChangePasswordResult() {
        return repository.getChangePasswordResult();
    }

    public LiveData<Boolean> getLogoutResult() {
        return logoutResult;
    }
}